#include "cairoicon.h"
#include <QPainter>

CairoIcon::CairoIcon(const QString & fileName,const QString & widgetName)
{
    this->setMaximumSize(80,160);
    this->setIcon(fileName);
    this->setName(widgetName);
    mn=1.0;
    x=pix.width();
 }

void CairoIcon::paintEvent ( QPaintEvent* ){
    QPainter painter(this);
    painter.scale(mn,mn);
    painter.drawPixmap(x,x,pix);
    if(!x){
        painter.setPen(QColor(0,10,0));
        painter.setBrush(QBrush(QLinearGradient()));
        painter.scale(.5,.5);
        painter.drawText(this->rect(),Qt::AlignBottom|Qt::AlignJustify|Qt::AlignHCenter,label);
    }
}
void CairoIcon::enterEvent ( QEvent *){
       mn=2.0;
       x=0;
       update();
}
void CairoIcon::leaveEvent ( QEvent * ){
        mn=1.0;
        x=pix.width()/2;
       update();
}
void CairoIcon::mousePressEvent ( QMouseEvent * ){
    emit clicked();
}
void CairoIcon::setIcon(const QString &fileName){
    pix.load(fileName);
    pix=pix.scaled(QSize(40,40));
}
void CairoIcon::setName(const QString &name){
        label=name;
}
